var request = require('request')


/*************************************************************************************
 * Description: 发送告警短信
 *      Author: xaj
 *        Date: 2017/09/30
 *   Parameter: phone,      string 通知的电话号码
 *              msg,        string 短信内容 eg: [征信] 验签失败
 *    Callback: promise
 *      Return: N/A
 *     Caution:
 *************************************************************************************/
function sendWarnMsg(phone, msg) {

    let url = 'http://td.51gjj.com:4821/JBServices/SendMsg';
    console.log('[sendWarnMsg] url: ' + url);
    let body = {"sdst": phone, "smsg": msg}
    console.log('[sendWarnMsg] body: ' + JSON.stringify(body));
    let options= {
        url: url,
        method: "POST",
        body: body,
        json: true,
        headers: {
            'content-type': 'application/json'
        }
    }
    request(options,(e,r,vb)=>{
        if(e) {
            console.error('[sendWarnMsg] sendWarnMsg error: ' + JSON.stringify(e));
        }
        else {
            if (vb.SendMsgResult == 'ok') {
                console.log('[sendWarnMsg] sendWarnMsg success: ' + JSON.stringify(vb))
            }
            else {
                console.log('[sendWarnMsg] sendWarnMsg error: ' + JSON.stringify(vb))
            }
        }
    })
}
/*************************************************************************************
 * Description: 发送告警短信
 *      Author: xaj
 *        Date: 2017/09/30
 *   Parameter: phone,      string 通知的电话号码    eg: '18857785871,17774010868'
 *              msg,        string 短信内容         eg: [征信] 验签失败 / 征信重启了 + 时间
 *    Callback: promise
 *      Return: N/A
 *     Caution:
 *************************************************************************************/
module.exports = sendWarnMsg;